package edu.westga.movierec.GUI;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSpinner;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.LayoutStyle;
import javax.swing.ListModel;
import javax.swing.SpinnerListModel;
import javax.swing.SpinnerNumberModel;
import javax.swing.SwingConstants;

import javax.swing.WindowConstants;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.SwingUtilities;

import edu.westga.movierec.model.*;
import java.awt.Component;
import edu.westga.movierec.controllers.*;

import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.DefaultComboBoxModel;
/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class AdminGUI extends javax.swing.JFrame {
	private JScrollPane MoviePanel;
	private JTable MovieTable;
	private JTextField movieInputField;
	private JButton changeRatingButton;
	private AbstractAction OpenUserMenu;
	private JMenuItem jMenuItem1;
	private JMenu jMenu1;
	private JMenuBar MovieMenuBar;
	private JList UserHistoryList;
	private JButton submitUserButton;
	private JLabel ListLabeler;
	private AbstractAction deleteMovieFromUserAction;
	private AbstractAction addMovieToUserAction;
	private AbstractAction abstractAction1;
	private JMenuItem jMenuItem3;
	private JMenu jMenu3;
	private JMenuBar jMenuBar1;
	private JTextField userMovieTextField;
	private AbstractAction CloseUserMenu;
	private JMenuItem jMenuItem2;
	private JMenu jMenu2;
	private JMenuBar UserMenuBar;
	private JButton deleteMovieFromUser;
	private JButton addMovieToUserButton;
	private AbstractAction closeMovie;
	private JScrollPane jScrollPane1;
	private JSpinner UserSpinner;
	private JDialog UserMenu;
	private JButton submitRatingButton;
	private AbstractAction submitRating;
	private AbstractAction movieSubmit;
	private JButton deleteMovieButton;
	private JButton addMovieButton;
	private JButton submitMovie;
	private AdminController theController;
	private JSpinner ChangeRatingSpinner;
	private AbstractAction changeRatingAction;
	private AbstractAction deleteButtonAction;
	private AbstractAction addMovieAction;

	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				AdminGUI inst = new AdminGUI();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}

		});
	}
	
	public AdminGUI() {
		super();
		theController = new AdminController();
		initGUI();
	}
	
	private void initGUI() {
		try {
			GroupLayout thisLayout = new GroupLayout((JComponent)getContentPane());
			getContentPane().setLayout(thisLayout);
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			this.setTitle("Admin Menu - Movies");
			this.setPreferredSize(new java.awt.Dimension(403, 288));
			{
				jMenuBar1 = new JMenuBar();
				setJMenuBar(getJMenuBar1());
				jMenuBar1.add(getJMenu3());
			}
			{
				UserMenuBar = new JMenuBar();
				setJMenuBar(getUserMenuBar());
				UserMenuBar.add(getJMenu2());
			}
			{
				MovieMenuBar = new JMenuBar();
				setJMenuBar(MovieMenuBar);
				MovieMenuBar.add(getJMenu1());
			}
			{
				changeRatingButton = new JButton();
				changeRatingButton.setText("Change Rating");
				changeRatingButton.setFont(new java.awt.Font("Segoe UI",0,12));
				changeRatingButton.setAction(getChangeRatingAction());
			}
			{
				deleteMovieButton = new JButton();
				deleteMovieButton.setText("Delete Movie");
				deleteMovieButton.setFont(new java.awt.Font("Segoe UI",0,12));
				deleteMovieButton.setAction(getDeleteButtonAction());
			}
			{
				addMovieButton = new JButton();
				addMovieButton.setText("Add Movie");
				addMovieButton.setFont(new java.awt.Font("Segoe UI",0,12));
				addMovieButton.setAction(getAddMovieAction());
			}
			{
				MoviePanel = new JScrollPane();
				{
					TableModel MovieTableModel = 
						new DefaultTableModel(
								new String[][] {{"",""}},
								//new String[][] { { "Saw", "42" }, { "Titanic", "16" } }
								new String[] { "Movie", "Rating" });
					MovieTable = new JTable();
					MoviePanel.setViewportView(getMovieTable());
					MovieTable.setModel(MovieTableModel);
					MovieTable.setColumnSelectionAllowed(false);
					MovieTable.setRowSelectionAllowed(true);
					MovieTable.setEnabled(true);
					
				}
			}
			{
				movieInputField = new JTextField();
			}
			{
				submitMovie = new JButton();
				submitMovie.setText("Submit");
				submitMovie.setAction(getMovieSubmit());
			}
			thisLayout.setVerticalGroup(thisLayout.createSequentialGroup()
				.addContainerGap()
				.addGroup(thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
				    .addComponent(submitMovie, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE)
				    .addComponent(movieInputField, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 27, GroupLayout.PREFERRED_SIZE))
				.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
				.addGroup(thisLayout.createParallelGroup()
				    .addGroup(thisLayout.createSequentialGroup()
				        .addComponent(MoviePanel, GroupLayout.PREFERRED_SIZE, 151, GroupLayout.PREFERRED_SIZE)
				        .addGap(0, 0, Short.MAX_VALUE))
				    .addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
				        .addComponent(addMovieButton, GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE)
				        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
				        .addComponent(deleteMovieButton, GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE)
				        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
				        .addComponent(changeRatingButton, GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE)
				        .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
				        .addComponent(getChangeRatingSpinner(), 0, 23, Short.MAX_VALUE)
				        .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
				        .addComponent(getSubmitRatingButton(), GroupLayout.PREFERRED_SIZE, 26, GroupLayout.PREFERRED_SIZE)))
				.addContainerGap(71, 71));
			thisLayout.setHorizontalGroup(thisLayout.createSequentialGroup()
				.addContainerGap()
				.addGroup(thisLayout.createParallelGroup()
				    .addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
				        .addComponent(MoviePanel, GroupLayout.PREFERRED_SIZE, 203, GroupLayout.PREFERRED_SIZE)
				        .addGap(6))
				    .addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
				        .addComponent(movieInputField, GroupLayout.PREFERRED_SIZE, 116, GroupLayout.PREFERRED_SIZE)
				        .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
				        .addComponent(submitMovie, GroupLayout.PREFERRED_SIZE, 81, GroupLayout.PREFERRED_SIZE)))
				.addGap(20)
				.addGroup(thisLayout.createParallelGroup()
				    .addGroup(thisLayout.createSequentialGroup()
				        .addComponent(addMovieButton, GroupLayout.PREFERRED_SIZE, 116, GroupLayout.PREFERRED_SIZE)
				        .addGap(0, 0, Short.MAX_VALUE))
				    .addGroup(thisLayout.createSequentialGroup()
				        .addComponent(deleteMovieButton, GroupLayout.PREFERRED_SIZE, 116, GroupLayout.PREFERRED_SIZE)
				        .addGap(0, 0, Short.MAX_VALUE))
				    .addGroup(thisLayout.createSequentialGroup()
				        .addComponent(changeRatingButton, GroupLayout.PREFERRED_SIZE, 116, GroupLayout.PREFERRED_SIZE)
				        .addGap(0, 0, Short.MAX_VALUE))
				    .addGroup(thisLayout.createSequentialGroup()
				        .addComponent(getSubmitRatingButton(), GroupLayout.PREFERRED_SIZE, 118, GroupLayout.PREFERRED_SIZE)
				        .addGap(0, 0, Short.MAX_VALUE))
				    .addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
				        .addGap(19)
				        .addComponent(getChangeRatingSpinner(), GroupLayout.PREFERRED_SIZE, 72, GroupLayout.PREFERRED_SIZE)
				        .addGap(0, 27, Short.MAX_VALUE)))
				.addContainerGap());
			thisLayout.linkSize(SwingConstants.VERTICAL, new Component[] {changeRatingButton, deleteMovieButton, addMovieButton});
			thisLayout.linkSize(SwingConstants.HORIZONTAL, new Component[] {changeRatingButton, deleteMovieButton, addMovieButton});
			pack();
			pack();
			pack();
			pack();
			pack();
			pack();
			this.setSize(403, 288);
			pack();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public JTable getMovieTable() {
		return MovieTable;
	}
	
	public JTextField getMovieInputField() {
		return movieInputField;
	}
	
	public JButton getAddMovieButton() {
		return addMovieButton;
	}
	
	public JButton getDeleteMovieButton() {
		return deleteMovieButton;
	}
	
	public JButton getChangeRatingButton() {
		return changeRatingButton;
	}
	
	public AbstractAction getMovieSubmit() {
		if(movieSubmit == null) {
			movieSubmit = new AbstractAction("Submit", null) {
				public void actionPerformed(ActionEvent evt) {
					String movieTitle = getMovieInputField().getText();
					DisplayDataInMovieTable(movieTitle);
				}
			};
		}
		return movieSubmit;
	}
	
	private AbstractAction getAddMovieAction() {
		if(addMovieAction == null) {
			addMovieAction = new AbstractAction("Add Movie", null) {
				public void actionPerformed(ActionEvent evt) {
					String movieTitle = getMovieInputField().getText();
					theController.addMovieToDatabase(movieTitle);
					DisplayDataInMovieTable(movieTitle);
				}
			};
		}
		return addMovieAction;
	}
	private void DisplayDataInMovieTable(String movieTitle){
		String[][] data = theController.getRatingsData(movieTitle);
		TableModel newModel = 
			new DefaultTableModel(data, new String[] { "Movie", "Rating" });
		getMovieTable().setModel(newModel);

	}
	
	private AbstractAction getDeleteButtonAction() {
		if(deleteButtonAction == null) {
			deleteButtonAction = new AbstractAction("Delete Movie", null) {
				public void actionPerformed(ActionEvent evt) {
					int selectedRow = getMovieTable().getSelectedRow();
					if(selectedRow==-1){
						return;
					}
					String movieTitle = (String) getMovieTable().getValueAt(selectedRow, 0);
					theController.deleteMovieFromDatabase(movieTitle);
					DisplayDataInMovieTable(movieTitle);
					getMovieInputField().setText(movieTitle);
				}
			};
		}
		return deleteButtonAction;
	}
	
	private AbstractAction getChangeRatingAction() {
		if(changeRatingAction == null) {
			changeRatingAction = new AbstractAction("Change Rating", null) {
				public void actionPerformed(ActionEvent evt) {
					getChangeRatingSpinner().setVisible(true);
					getSubmitRatingButton().setVisible(true);
				}
			};
		}
		return changeRatingAction;
	}
	
	private JSpinner getChangeRatingSpinner() {
		if(ChangeRatingSpinner == null) {
			SpinnerNumberModel RateSpinnerModel =
				new SpinnerNumberModel(1,-1000,1000,0);
			ChangeRatingSpinner = new JSpinner();
			ChangeRatingSpinner.setModel(RateSpinnerModel);
			ChangeRatingSpinner.setEnabled(true);
			ChangeRatingSpinner.setVisible(false);
		}
		return ChangeRatingSpinner;
	}

	public AbstractAction getSubmitRating() {
		if(submitRating == null) {
			submitRating = new AbstractAction("Submit Rating", null) {
				public void actionPerformed(ActionEvent evt) {
					int selectedRow = getMovieTable().getSelectedRow();
					if(selectedRow==-1){
						return;
					}
					String input  = getMovieInputField().getText();
					String output = (String) getMovieTable().getValueAt(selectedRow, 0);
					int rating = Integer.parseInt(getChangeRatingSpinner().getValue().toString());
					theController.changeMovieRating(input, output, rating);
					DisplayDataInMovieTable(input);
					getChangeRatingSpinner().setVisible(false);
					getSubmitRatingButton().setVisible(false);
				}
			};
		}
		return submitRating;
	}
	
	public JButton getSubmitRatingButton() {
		if(submitRatingButton == null) {
			submitRatingButton = new JButton();
			submitRatingButton.setText("Submit Rating");
			submitRatingButton.setAction(getSubmitRating());
			submitRatingButton.setFont(new java.awt.Font("Segoe UI",0,12));
			submitRatingButton.setVisible(false);
		}
		return submitRatingButton;
	}
	
	public JDialog getUserMenu() {
		if(UserMenu == null) {
			UserMenu = new JDialog(this);
			GroupLayout UserMenuLayout = new GroupLayout((JComponent)UserMenu.getContentPane());
			UserMenu.getContentPane().setLayout(UserMenuLayout);
			UserMenu.setTitle("Admin Menu - User");
			UserMenuLayout.setHorizontalGroup(UserMenuLayout.createSequentialGroup()
				.addContainerGap()
				.addGroup(UserMenuLayout.createParallelGroup()
				    .addGroup(GroupLayout.Alignment.LEADING, UserMenuLayout.createSequentialGroup()
				        .addComponent(getUserSpinner(), GroupLayout.PREFERRED_SIZE, 76, GroupLayout.PREFERRED_SIZE)
				        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
				        .addComponent(getSubmitUserButton(), GroupLayout.PREFERRED_SIZE, 85, GroupLayout.PREFERRED_SIZE))
				    .addComponent(getJScrollPane1(), GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 167, GroupLayout.PREFERRED_SIZE))
				.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
				.addGroup(UserMenuLayout.createParallelGroup()
				    .addGroup(GroupLayout.Alignment.LEADING, UserMenuLayout.createSequentialGroup()
				        .addComponent(getListLabeler(), GroupLayout.PREFERRED_SIZE, 106, GroupLayout.PREFERRED_SIZE)
				        .addGap(0, 11, Short.MAX_VALUE))
				    .addGroup(UserMenuLayout.createSequentialGroup()
				        .addComponent(getDeleteMovieFromUser(), GroupLayout.PREFERRED_SIZE, 116, GroupLayout.PREFERRED_SIZE)
				        .addGap(0, 0, Short.MAX_VALUE))
				    .addGroup(UserMenuLayout.createSequentialGroup()
				        .addComponent(getAddMovieToUserButton(), GroupLayout.PREFERRED_SIZE, 115, GroupLayout.PREFERRED_SIZE)
				        .addGap(0, 0, Short.MAX_VALUE))
				    .addComponent(getUserMovieTextField(), GroupLayout.Alignment.LEADING, 0, 117, Short.MAX_VALUE))
				.addContainerGap(31, 31));
			UserMenuLayout.setVerticalGroup(UserMenuLayout.createSequentialGroup()
				.addContainerGap()
				.addGroup(UserMenuLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
				    .addComponent(getUserSpinner(), GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 26, GroupLayout.PREFERRED_SIZE)
				    .addComponent(getSubmitUserButton(), GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
				.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
				.addGroup(UserMenuLayout.createParallelGroup()
				    .addGroup(GroupLayout.Alignment.LEADING, UserMenuLayout.createSequentialGroup()
				        .addComponent(getUserMovieTextField(), GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
				        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
				        .addComponent(getAddMovieToUserButton(), GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
				        .addGap(0, 35, GroupLayout.PREFERRED_SIZE)
				        .addComponent(getListLabeler(), GroupLayout.PREFERRED_SIZE, 18, GroupLayout.PREFERRED_SIZE)
				        .addComponent(getDeleteMovieFromUser(), 0, 21, Short.MAX_VALUE))
				    .addGroup(UserMenuLayout.createSequentialGroup()
				        .addComponent(getJScrollPane1(), GroupLayout.PREFERRED_SIZE, 124, GroupLayout.PREFERRED_SIZE)
				        .addGap(0, 0, Short.MAX_VALUE)))
				.addContainerGap(27, 27));
		}
		return UserMenu;
	}
	
	private JSpinner getUserSpinner() {
		if(UserSpinner == null) {
			SpinnerNumberModel UserSpinnerModel =
				new SpinnerNumberModel(1,0,1000,1);
			UserSpinner = new JSpinner();
			UserSpinner.setModel(UserSpinnerModel);
		}
		return UserSpinner;
	}
	
	public JButton getSubmitUserButton() {
		if(submitUserButton == null) {
			submitUserButton = new JButton();
			submitUserButton.setText("Submit");
			submitUserButton.setAction(getAbstractAction1());
			submitUserButton.setFont(new java.awt.Font("Segoe UI",0,12));
		}
		return submitUserButton;
	}

	private JScrollPane getJScrollPane1() {
		if(jScrollPane1 == null) {
			jScrollPane1 = new JScrollPane();
			jScrollPane1.setViewportView(getUserHistoryList());
		}
		return jScrollPane1;
	}
	
	public JList getUserHistoryList() {
		if(UserHistoryList == null) {
			ListModel UserHistoryListModel = 
				new DefaultComboBoxModel(
						new String[] {""});
			UserHistoryList = new JList();
			UserHistoryList.setModel(UserHistoryListModel);
			UserHistoryList.setPreferredSize(new java.awt.Dimension(164, 121));
		}
		return UserHistoryList;
	}
	
	private JMenu getJMenu1() {
		if(jMenu1 == null) {
			jMenu1 = new JMenu();
			jMenu1.setText("File");
			jMenu1.add(getJMenuItem1());
		}
		return jMenu1;
	}
	
	private JMenuItem getJMenuItem1() {
		if(jMenuItem1 == null) {
			jMenuItem1 = new JMenuItem();
			jMenuItem1.setText("jMenuItem1");
			jMenuItem1.setAction(getOpenUserMenu());
		}
		return jMenuItem1;
	}
	
	public AbstractAction getOpenUserMenu() {
		if(OpenUserMenu == null) {
			OpenUserMenu = new AbstractAction("Open User Admin", null) {
				public void actionPerformed(ActionEvent evt) {
					getUserMenu().pack();
					getUserMenu().setLocationRelativeTo(null);
					getUserMenu().setVisible(true);
				}
			};
		}
		return OpenUserMenu;
	}
	
	public JButton getAddMovieToUserButton() {
		if(addMovieToUserButton == null) {
			addMovieToUserButton = new JButton();
			addMovieToUserButton.setText("Add Movie");
			addMovieToUserButton.setFont(new java.awt.Font("Segoe UI",0,12));
			addMovieToUserButton.setAction(getAddMovieToUserAction());
		}
		return addMovieToUserButton;
	}
	
	public JButton getDeleteMovieFromUser() {
		if(deleteMovieFromUser == null) {
			deleteMovieFromUser = new JButton();
			deleteMovieFromUser.setText("Delete Movie");
			deleteMovieFromUser.setFont(new java.awt.Font("Segoe UI",0,12));
			deleteMovieFromUser.setAction(getDeleteMovieFromUserAction());
		}
		return deleteMovieFromUser;
	}
	
	public JMenuBar getUserMenuBar() {
		return UserMenuBar;
	}
	
	private JMenu getJMenu2() {
		if(jMenu2 == null) {
			jMenu2 = new JMenu();
			jMenu2.setText("File");
			jMenu2.add(getJMenuItem2());
		}
		return jMenu2;
	}
	
	private JMenuItem getJMenuItem2() {
		if(jMenuItem2 == null) {
			jMenuItem2 = new JMenuItem();
			jMenuItem2.setText("jMenuItem2");
			jMenuItem2.setAction(getCloseUserMenu());
		}
		return jMenuItem2;
	}
	
	public AbstractAction getCloseUserMenu() {
		if(CloseUserMenu == null) {
			CloseUserMenu = new AbstractAction("Close User Menu", null) {
				public void actionPerformed(ActionEvent evt) {
					getUserMenu().dispose();
				}
			};
		}
		return CloseUserMenu;
	}
	
	private JTextField getUserMovieTextField() {
		if(userMovieTextField == null) {
			userMovieTextField = new JTextField();
		}
		return userMovieTextField;
	}
	
	public JMenuBar getJMenuBar1() {
		return jMenuBar1;
	}
	
	private JMenu getJMenu3() {
		if(jMenu3 == null) {
			jMenu3 = new JMenu();
			jMenu3.setText("File");
			jMenu3.add(getJMenuItem3());
		}
		return jMenu3;
	}
	
	private JMenuItem getJMenuItem3() {
		if(jMenuItem3 == null) {
			jMenuItem3 = new JMenuItem();
			jMenuItem3.setAction(getCloseUserMenu());
		}
		return jMenuItem3;
	}
	
	public AbstractAction getAbstractAction1() {
		if(abstractAction1 == null) {
			abstractAction1 = new AbstractAction("Submit", null) {
				public void actionPerformed(ActionEvent evt) {
					int userID = Integer.parseInt(getUserSpinner().getValue().toString());
					DisplayUserHistoryData(userID);
				}
			};
		}
		return abstractAction1;
	}
	
	public AbstractAction getAddMovieToUserAction() {
		if(addMovieToUserAction == null) {
			addMovieToUserAction = new AbstractAction("Add Movie", null) {
				public void actionPerformed(ActionEvent evt) {
					String movieTitle = getUserMovieTextField().getText();
					int userID = Integer.parseInt(getUserSpinner().getValue().toString());
					theController.addMovieToUser(userID, movieTitle);
					DisplayUserHistoryData(userID);
				}
			};
		}
		return addMovieToUserAction;
	}
	private void DisplayUserHistoryData(int userID){
		ListModel UserHistoryListModel = 
			new DefaultComboBoxModel(
					theController.getUserHistory(userID));
		UserHistoryList.setModel(UserHistoryListModel);
		UserHistoryList.setPreferredSize(new java.awt.Dimension(164, 98));
	}
	
	public AbstractAction getDeleteMovieFromUserAction() {
		if(deleteMovieFromUserAction == null) {
			deleteMovieFromUserAction = new AbstractAction("Delete Movie", null) {
				public void actionPerformed(ActionEvent evt) {
					String movieTitle = (String) getUserHistoryList().getSelectedValue();
					if(movieTitle==null){
						return;
					}
					int userID = Integer.parseInt(getUserSpinner().getValue().toString());
					theController.deleteMovieFromUser(userID, movieTitle);
					DisplayUserHistoryData(userID);
				}
			};
		}
		return deleteMovieFromUserAction;
	}
	
	private JLabel getListLabeler() {
		if(ListLabeler == null) {
			ListLabeler = new JLabel();
			ListLabeler.setText("Select from list:");
		}
		return ListLabeler;
	}

}
